package org.msd.controller;
import org.apache.ibatis.annotations.Param;
import org.msd.model.Information;
import org.msd.service.iml.Registered;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/login")
public class Logcontrollwe {

  @Autowired
  private Registered  registered;//注册 登入 功能实现


    @RequestMapping("logion")
    //跳转到登入页面
    public String LongIN(){

        return "index11";
    }
    /*
    登入验证
     */
    @RequestMapping("sign")
    public String Logfin(Model model,@Param("name") String name, @Param("password") String password){


        Information information=registered.querycondition(name,password);

        if (information!=null){
            model.addAttribute("username",information.getName());
            return "Test";
        }

        model.addAttribute("login","账号或密码错误");
        //失败就跳转到主页面
        return "redirect:index11";
    }
    /*
    注册页面 跳转到注册页面
     */
    @RequestMapping("regis")
    public String registration(){
        return "Registrationfailed";

    }
    @RequestMapping("tered")
    public String regisTered(Model model,Information information){



     int Registrationfunction=registered.registered(information);

       if (Registrationfunction==1){

           return "redirect:Registration";//返回注册成功页面

       }else{

         model.addAttribute("mag","注册失败");

         return "redirect:Registrationfailed";//返回注册失败页面
       }

    }
    /*
    注册成功 提交的页面  返回主页面
     */
    @RequestMapping("registrationsuccess")

    public String  registrationsuccess(){

        return "redirect:index11";
    }
    /*
    修改密码
     */
    @RequestMapping("change")
    public ModelAndView ChangePassword( @Param("password") String password ,@Param("cellphonenumber")String cellphonenumber){

        ModelAndView modelAndView=new ModelAndView("Test");

       int i=registered.changePassword(cellphonenumber,password);

       if (i==1){

           modelAndView.addObject("uqdate","修改成功");
           return modelAndView;

       }else{
           modelAndView.addObject("uqdate","重新修改");
           return modelAndView;
       }
    }
   @RequestMapping("/yusd")//接收参数 进行查询并保存到Medal里面传递到Test页面
    public String  add(@RequestParam("id")int id){
        return "Test";//跳转到Test页面
   }
}
